package demo1.Test;
import java.util.Arrays;
import java.util.Comparator;
class Student implements Comparable<Student> {
    int age;
    String name;
    int score;
    public Student(String name, int age, int score) {
        this.age = age;
        this.name = name;
        this.score = score;
    }

    @Override
    public String toString() {
        return "Student{" +
                "age=" + age +
                ", name='" + name + '\'' +
                ", score=" + score +
                '}';
    }

    @Override
    public int compareTo(Student o) {
        return this.age - o.age;//将年龄从小到达排序
    }
}
public class c {
    public static void main(String[] args) {
    Student[] student = new Student[4];
    student[0] = new Student("lisi",18,88);
    student[1] = new Student("avb",15,99);
    student[2] = new Student("shabihan",112,99);
    student[3] = new Student("zhshan",10,99);
    System.out.println(Arrays.toString(student));
    Arrays.sort(student);
    System.out.println(student[0].compareTo(student[2]));
    System.out.println(Arrays.toString(student));
    }
}
